package hello;

import org.hibernate.Session;
import org.hibernate.Transaction;

import persistence.HibernateUtil;
import auction.model.Bid;
import auction.model.Item;

public class HelloWorldParentChildren
{
	
	
	public static void main(String[] args)throws Exception
	{
		
		Session s=HibernateUtil.getSessionFactory().openSession();
		Transaction tx=s.beginTransaction();
		
		Item item=new Item("tt");
		Bid bid=new Bid();
		//User user=new User("wei");
		item.addBid(bid);
		bid.setItem(item);
		//user.addBid(bid);
		//s.save(user);
		//s.save(item);
		//s.save(bid);
		
		
		tx.commit();
		s.close();
		
		
		
		Session s1=HibernateUtil.getSessionFactory().openSession();
		Transaction tx1=s1.beginTransaction();
		//update a detached object will cause update sql even this don't change
		//item.setTitle("222");
		//s1.update(item);
		
		Item loadi=(Item)s1.load(Item.class, 1L);
		s1.delete(loadi);
		/*
		
		Bid loadbid=(Bid)s1.load(Bid.class, 2L);
		
		loadi.addBid(loadbid);
		loadi.getBids().remove(loadbid);
		*/
		
		tx1.commit();
		s1.close();
		
		
		
		//HibernateUtil.stat();
		HibernateUtil.shutdown();
	}
	
	public static void getParent(Class clazz)
	{
		Class parent=clazz.getSuperclass();
	  if(parent !=null)
	  {
			System.out.println("###"+parent.getName());
			getParent(parent);
		}
	}
	
	static void out(Object obj)
	{
		System.out.println(obj);
	}
}
